<template>
  <div v-if="$store.state.edit.row">
    <span
      v-for="(value, key) in $store.state.edit.row.fields"
      :key="key"
      class="ml10"
    >
      <label>
        <input
          size="mini"
          type="checkbox"
          :value="key"
          v-model="$store.state.edit.row['selectedFields']"
        />
        {{ value }}
      </label>
    </span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selected: []
    };
  },
  methods: {
    validate() {
      if (this.$store.state.edit.row["selectedFields"].length == 0) {
        this.$store.dispatch("commitError", "请先选择导出字段");
        return false;
      }
      if (this.$store.state.edit.row["query"] == "") {
        if (this.$store.state.edit.row["ids"].length == 0) {
          this.$store.dispatch("commitError", "请先选择导出行");
          return false;
        }
      } else {
        if (this.$store.state.main.pageData.queryPage.total == 0) {
          this.$store.dispatch("commitError", "搜索结果数据为0行, 无法导出");
          return false;
        }
        if (this.$store.state.main.pageData.queryPage.total > 50000) {
          this.$store.dispatch(
            "commitError",
            "系统不支持超过50000行的数据导出"
          );
          return false;
        }
      }
      return true;
    },
    callbefore() {
      if (this.$store.state.edit.row["query"]) {
        return;
      }
      var ids = [];
      for (var k in this.$store.state.main.selectedRows) {
        var v = this.$store.state.main.selectedRows[k];
        if (v) {
          ids.push(k);
        }
      }
      this.$store.state.edit.row["ids"] = ids;
    },
    callafter(response) {
      this.$store.dispatch("timerTasks");
    }
  }
};
</script>
